const app = getApp()
import Api from '../../utils/api';
import util from '../../utils/util';
let wxbarcode = require('../../utils/index.js');
var trimer;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderItem: '',
    address: '',
    istemplate: false,
    orderStatusIndex: 0,
    orderStatusText: ['拼团中', '待付款', '待接单', '待收货', '待评价', '已完成', '已取消'],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var orderItem = JSON.parse(options.order);
    console.log(orderItem.receiveAddress,'=============订单地址')
    this.setData({
      orderItem: orderItem ,
      orderStatusIndex: options.orderStatusIndex,
      address: orderItem.receiveAddress,
    })
    console.log(this.data.orderItem)

    this.isProductRelease();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    app.globalData.otherPageHideFlag = true;
  },
  //判断产品发布信息
  isProductRelease() {
    let _this = this;
    Api.isProductRelease().then(res => {
      console.log('进入标记查询', res)
      _this.setData({
        istemplate: res.data
      })
    }).catch(err => {
      _this.setData({
        istemplate: true
      })
    });
  },
   //跳转店铺
  toShopPage(e) {
    var that=this;
    console.log('店铺跳转', e);
    let order = e.currentTarget.dataset.order;
    let shop = e.currentTarget.dataset.shop;
    if (order.orderTableType != 'COMMON_ORDER') {
      //跳转拼团列表
      wx.navigateTo({
        url: '/pages/activityList/activityList',
      })
    } else {
      //跳转店铺
      wx.navigateTo({
        url: `/pages/shopClass/shopClass?id=${shop.id}`,
      })
    }
  },
  //商品详情跳转
  toGoodsDesc(e) {
    console.log('商品跳转', e);
    let type = e.currentTarget.dataset.type;
    let item = e.currentTarget.dataset.item;
    if (type != 'COMMON_ORDER') {
      wx.showToast({
        icon: 'none',
        title: '拼团商品不能进入详情',
      })
    } else {
      wx.navigateTo({
        url: `/pages/details/shopDetail?id=${item.goodsId}`,
      })
    }
  },
  copy(e) {
    var that = this;
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        // console.log(res)
        wx.getClipboardData({
          success: function (res) {
            // console.log(res)
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },

})